home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / switcher.lzh / DRPS.C next >
C/C++ Source or Header  |  1990-04-04  |  2KB  |  104 lines

  1. #include <tos.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <mydefs.h>
  6.  
  7. char buf[1024];
  8. char ppath[128],dpath[128],ppat2[128];
  9. char files[128][14];
  10. long fleng[128],l;
  11.  
  12. static char *pext  = "\\*.PI3";
  13. static char *dfile = "\\DESKTOP.PI3";
  14.  
  15. long getline(
  16.     char    *dest,
  17.     char    *buf,
  18.     long    start,
  19.     long    max)
  20.     {
  21.     long p,q;
  22.     
  23.     q = 0L;
  24.     p = start;
  25.     while((p<max)&&(*(buf+p)<0x20))
  26.         ++p;
  27.     while((p<max)&&(*(buf+p)>0x1f))
  28.         {
  29.         *(dest+q)=*(buf+p);
  30.         ++p;
  31.         ++q;
  32.         }
  33.     *(dest+q) = 0;
  34.     return(p);
  35.     }
  36.  
  37. void main(void)
  38.     {
  39.     int fd;
  40.     DTA *d;
  41.     unt u;
  42.     uln    r;
  43.     char *loc;
  44.     static char *backs="\\";
  45.  
  46.     puts("DRPS V2.0 - with Turbo C 2.0");
  47.     puts("DegaDesk Random Picture Selector");
  48.     puts("BY Gregory Mathias Lemperle-Kerr");
  49.  
  50.     if (Fsfirst("DRPS.INF",0)>=0)
  51.         {
  52.         d=Fgetdta();
  53.         l=d->d_length;
  54.         puts("Using DRPS.INF for paths...");
  55.         fd=Fopen("DRPS.INF",1);
  56.         Fread(fd,l,buf);
  57.         Fclose(fd);
  58.         getline(dpath,buf,getline(ppath,buf,0,l),l);
  59.         }
  60.     else
  61.         {
  62.         strcpy(ppath,"E:\\CLIPART");
  63.         strcpy(dpath,"C:\\AUTO\\UNUSED");
  64.         }
  65.     *(pext+5)=(*(dfile+11)='1'+Getrez());
  66.     strcpy(ppat2,ppath);
  67.     strcat(ppath,pext);
  68.     strcat(dpath,dfile);
  69.     strcat(ppat2,backs);
  70.     puts(ppath);
  71.     puts(dpath);
  72.  
  73.     u = 0;
  74.     if ((fd=Fsfirst(ppath,0))>=0) while (fd>=0)
  75.         {
  76.         d=Fgetdta();
  77.         strncpy(files[u],d->d_fname,14);
  78.         fleng[u]=d->d_length;
  79.         fd = Fsnext();
  80.         ++u;
  81.         }
  82.     else
  83.         {
  84.         puts("NO PICTURES FOUND!\007");
  85.         return;
  86.         }
  87.     r=(Random()+Gettime())%u;
  88.     puts(files[r]);
  89.     puts("Copying...");    
  90.     if(Fsfirst(dpath,0)<0)
  91.         {
  92.         fd=Fcreate(dpath,0);
  93.         Fclose(fd);    
  94.         }
  95.     loc = (char *)Physbase()-34;
  96.     strcat(ppat2,files[r]);
  97.     fd=Fopen(ppat2,READ);
  98.     Fread(fd,fleng[r],loc);
  99.     Fclose(fd);
  100.     fd=Fopen(dpath,WRITE);
  101.     Fwrite(fd,fleng[r],loc);
  102.     Fclose(fd);
  103.     }
  104.